package com.xlh.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xlh.Utils.Constant;
import com.xlh.Utils.FUti;
import com.xlh.bean.TitleBean;
import com.xlh.interf.IAdapter;
import com.xlh.outside.R;

import java.util.ArrayList;
import java.util.List;

public class OtherExitsAdapter extends BaseAdapter implements IAdapter{

	private List<TitleBean> data;
	private LayoutInflater mInflater;
	private Context context;


	public OtherExitsAdapter(Context context, List<TitleBean> data) {
			// TODO Auto-generated constructor stub
		this.context = context;
		mInflater = LayoutInflater.from(context);
		this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data == null ? 0 : data.size();
	} 
	public TitleBean getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ViewHolder holder;

		if (convertView == null) {
			convertView 	= mInflater.inflate(R.layout.other_exit_item, parent, false);
			holder 			= new ViewHolder();
			holder.tvName 	= (TextView) convertView.findViewById(R.id.title_text);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		TitleBean titleBean = data.get(position);
		

		ViewGroup.LayoutParams vLparam 	= holder.tvName.getLayoutParams();
		vLparam.height 					= FUti.dip2px(context,titleBean.getHeight());

//		GradientDrawable drawable = (GradientDrawable) holder.tvName.getBackground();
//		//边框
//		//drawable.setStroke(FUti.dip2px(convertView.getContext(),1), Color.parseColor( Constant.getAppColor().getButBorderColor() ));
//
//		//设置背景
//		drawable.setColor(Color.parseColor(Constant.getAppColor().getButBackColor()));



		holder.tvName.setTextColor(Color.parseColor(Constant.getAppColor().getFontColor() ));
		holder.tvName.getLayoutParams().height = FUti.dip2px(convertView.getContext(),30);
		holder.tvName.setText(  titleBean.getSpanned() );
		return convertView;
	}



	private class ViewHolder {
		private TextView tvName;
	}
	


	public void setData(List<TitleBean> mTitleData) {
		// TODO Auto-generated method stub
		if(mTitleData != null) {
			this.data = mTitleData;
		}
		this.notifyDataSetChanged();
	}

	public void clear() {
		// TODO Auto-generated method stub
		if(data != null) {
			data.clear();
		}
		this.notifyDataSetChanged();
	}






	@Override
	public <T> void addData(T data) {
		if(this.data != null) {
			this.data.add((TitleBean)data);
		}
	}

	@Override
	public <T> IAdapter setDatas(List<T> datas) {
			this.data = (List<TitleBean>) datas;
			return this;
	}

	public void update(){
		this.notifyDataSetChanged();
	}

	
}
